home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Online / Apache / cgi-bin / testform.rexx < prev    next >
OS/2 REXX Batch file  |  1997-06-11  |  2KB  |  83 lines

  1. /* Parses test form */
  2.  
  3. options results
  4.  
  5. say "Content-Type: text/html"
  6. say ""
  7.  
  8. getvar REQUEST_METHOD
  9. method = result
  10.  
  11. getvar CONTENT_TYPE
  12. type = result
  13.  
  14. getvar CONTENT_LENGTH
  15. length = result
  16.  
  17. getvar QUERY_STRING
  18. query = result
  19.  
  20. /* used on GET form queries */
  21. if length(query) > 0 then do
  22.  /* go through the query string extracting name, value pairs */
  23.  do forever while length(query) > 0
  24.     parse var query name '=' value '&'
  25.     value = plus_to_space(unescape_url(value))
  26.     echo "<LI>name is " || name || ", value is " || value
  27.     /* advances query to the next name=value pair */
  28.     spot = index(query,"&")
  29.     if (spot ~= 0) then  query = substr(query,index(query,"&")+1)
  30.     else query = ""
  31.  end
  32. end
  33.  
  34. say "<UL>"
  35. say "<LI> method is " || method
  36. say "<LI> type is " || type
  37. say "<LI> length is " || length
  38. say "<LI> query is " || query
  39.  
  40. /* used on POST queries */
  41. word = getword("")
  42. do forever while word ~ = ""
  43.     parse var word name '=' value
  44.     say "<LI>name is " || name
  45.     say "value is " || value
  46.     word = getword("")
  47. end
  48.  
  49. say "</ul>"
  50. exit
  51.  
  52. /* used in POST queries, gets a name=value pair from stdin */
  53. getword : procedure
  54.     retval = ""
  55.     do forever while (eof(stdin) = 0)
  56.     ch = readch(stdin,1)
  57.     if ch = -1 then leav e
  58.     if ch = '&' then leave
  59.     retval = retval ||  ch
  60.     end
  61.  return unescape_url(plus_to_space(retval))
  62.  
  63. /* Converts the "+" in the url to spaces */
  64. plus_to_space : procedure
  65.     ARG url
  66.     return translate(url, " ", "+")
  67.  
  68. /* change %xx to the ascii equivalent - eg %20 is a space */
  69. unescape_url : procedure
  70.     ARG url
  71.     retval = ""
  72.     do i = 1 to length(url)
  73.     chr = substr(url,i,1)
  74.     if chr = '%' then do
  75.         chr = substr(url,i+1,2);
  76.         newchr = x2c(chr)
  77.         retval = retval || newchr
  78.         i = i + 2
  79.     end
  80.     else retval = retval || chr
  81.     end
  82. return retval
  83.